﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationSACC.aspx.cs" Inherits="CRMWeb.Pages.Application.ApplicationSACC" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>SACC TAB in Application Profile </title>
    <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="/Css/CrmStyle.css" />
    <script type="text/javascript" src="/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/EasyUI/jquery.easyui.min.js"></script>

</head>
<body>
    <form id="form1" runat="server">
        <div data-options="region:'south'" style="height: auto;">
            <input id="hdnVerifyStatusID" type="hidden" />
            <table style="width: 90%; height: auto;">
                <tr>
                    <td style="width: 50%; text-align: center">
                        <div class="ftitle">
                            Member Web Control
                        </div>
                    </td>
                    <td style="width: 25%; text-align: center">
                        <div class="ftitle">
                            Assesment
                        </div>
                    </td>
                    <td style="width: 25%; text-align: center">
                        <div class="ftitle">
                            Settlement
                        </div>
                    </td>
                </tr>
            </table>
            <%-- <asp:ScriptManager ID="sm1" runat="server" EnablePageMethods="true" ScriptMode="Release"></asp:ScriptManager>--%>
            <table style="width: 90%; height: auto; padding: 10px">
                <tr>
                    <td style="width: 40%; vertical-align: top; border-right: 5px solid #E6EEFF">
                        <table id="tbpart1" style="width: 100%; height: auto; padding: 5px">
                            <tr>
                                <td style="width: 20%"></td>
                                <td style="width: 10%"><b>Attampts</b> </td>
                                <td style="width: 10%"><b>Status</b> </td>
                                <td style="width: 20%"></td>
                                <td style="width: 22%"></td>
                                <td style="width: 18%"><b>Downloaded</b> </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>ID </td>
                                <td></td>
                                <td>
                                    <input id="chkID" type="checkbox" onclick="formDataChange();" /></td>
                                <td></td>
                                <td>
                                    <%--<asp:Button ID="btnIDCheck" runat="server" Text="Download" CssClass="blueButton" OnClick="btnIDCheck_Click" />--%>
                                    <a href="javascript:void(0)" class="easyui-linkbutton" id="btnIDCheck" disabled="true" onclick="downloadFile('IDCheckFile')">Download </a>
                                    <asp:HiddenField ID="hdnIDCheckFile" runat="server" />
                                </td>
                                <td style="text-align: center; font-family: Arial; font-weight: bold">
                                    <label id="lblIDCount"></label>
                                </td>
                            </tr>
                            <tr>
                                <td>Bank Retrieve </td>
                                <td style="text-align: center; font-family: Arial; font-weight: bold">
                                    <label id="lblbankAttempts">00 </label>
                                </td>
                                <td>
                                    <input id="chkBank" type="checkbox" onclick="formDataChange();" /></td>
                                <td>
                                    <a id="lnkResetBank" href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#lblbankAttempts').html('00')">Reset </a></td>
                                <td>
                                    <a id="btnBank" href="javascript:void(0)" disabled="true" class="easyui-linkbutton">Download </a>

                                </td>
                                <td style="text-align: center; font-family: Arial; font-weight: bold">
                                    <label id="lblBankFileCount"></label>
                                </td>
                            </tr>
                            <tr>
                                <td>Pay Slip </td>
                                <td></td>
                                <td>
                                    <input id="chkPayslip" type="checkbox" onclick="formDataChange();" /></td>
                                <td></td>
                                <td>
                                    <a href="javascript:void(0)" class="easyui-linkbutton" id="btnPayslip" disabled="true" onclick="downloadFile('PayslipFile')">Download </a>
                                </td>
                                <td style="text-align: center; font-family: Arial; font-weight: bold">
                                    <label id="lblPayslipCount"></label>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td style="width: 20%; vertical-align: top; border-right: 5px solid #E6EEFF">
                        <table id="tbpart2" style="width: 90%; height: auto; padding: 5px">
                            <tr>
                                <td></td>
                                <td><b>Status</b> </td>
                            </tr>

                            <tr>
                                <td>Credit History </td>
                                <td>
                                    <input id="chkCreditHistory" type="checkbox" onclick="formDataChange();" />
                                </td>
                            </tr>
                            <tr>
                                <td>I & E </td>
                                <td>
                                    <input id="chkIE" type="checkbox" onclick="formDataChange();" />
                                </td>
                            </tr>
                            <tr></tr>
                            <tr></tr>
                            <tr></tr>
                        </table>
                    </td>
                    <td style="width: 20%; vertical-align: top">
                        <table id="tbpart3" style="width: 90%; height: auto; padding: 5px">
                            <tr>
                                <td></td>
                                <td><b>Status</b> </td>
                            </tr>

                            <tr>
                                <td>Phone Verification </td>
                                <td>
                                    <input id="chkPhone" type="checkbox" onclick="formDataChange();" />
                                </td>
                            </tr>
                            <tr>
                                <td>Contract Prepared </td>
                                <td>
                                    <input id="chkContract" type="checkbox" onclick="formDataChange();" />
                                </td>
                            </tr>
                            <tr>
                                <td>Contract e-Signed </td>
                                <td>
                                    <input id="chkesign" type="checkbox" onclick="formDataChange();" />
                                </td>
                            </tr>
                            <tr>
                                <td>Fund Transferred (RTGS) </td>
                                <td>
                                    <input id="chkFund" type="checkbox" onclick="formDataChange();" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>

        </div>

    </form>
    <script type="text/javascript">
        function showPrompt() {
            return 'You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?';
        }
        function formDataChange() {
            window.onbeforeunload = showPrompt;
        }

        $(document).ready(function () {

            $('#ContentPlaceHolder1_appProfile_hdnSACC').val('true');
            bindVerificationData();
        });

        function updateDownloadCount(field, currentCount) {
            $.ajax({
                url: '/WebServices/ApplicationSACC.ashx?method=updateDownloadCount',
                data: {
                    app_id: getQuerystring('app_id', ''),
                    fieldName: field,
                    newCount: currentCount
                },
                success: function (data) {
                    if (data == 'True') {
                        if (field == 'IDfiledownloaded')
                            $('#lblIDCount').html(currentCount);
                        else if (field == 'payslipdownloaded')
                            $('#lblPayslipCount').html(currentCount);
                    }
                },
                error: function () {
                    $.messager.alert('Morgan CRM', '<span style="color:red;font-family:Arial;text-align:center;font-size:12px;font-weight:bold">Server Error </span>');
                    return;
                }
            });
        }
        function downloadFile(fileType) {
            $.ajax({
                url: '/WebServices/DownloadFiles.ashx?app_id=' + getQuerystring('app_id', '') + "&fileType=" + fileType,
                success: function (data) {

                    if (data == '0') {
                        $.messager.alert('Morgan CRM', '<span style="color:red;font-family:Arial;text-align:center;font-size:12px;font-weight:bold"> File not found </span>');
                        return;
                    }
                    else {
                        var newFileCount = 0;
                        var fieldName = '';
                        var iframe = document.createElement("iframe");
                        iframe.src = encodeURI("/WebServices/DownloadFiles.ashx?app_id=" + getQuerystring('app_id', '') + "&fileType=" + fileType);
                        iframe.style.display = "none";
                        document.body.appendChild(iframe);

                        if (fileType == 'IDCheckFile') {
                            newFileCount = $('#lblIDCount').text();
                            newFileCount = +newFileCount + 1;
                        }
                        else if (fileType == 'PayslipFile') {
                            newFileCount = $('#lblPayslipCount').text();
                            newFileCount = +newFileCount + 1;
                        }

                        if (fileType == 'IDCheckFile')
                            fieldName = 'IDfiledownloaded';
                        else if (fileType == 'PayslipFile')
                            fieldName = 'payslipdownloaded';

                        updateDownloadCount(fieldName, newFileCount);
                    }
                },
                error: function () {
                    $.messager.alert('Morgan CRM', '<span style="color:red;font-family:Arial;text-align:center;font-size:12px;font-weight:bold"> Server Error </span>');
                }
            });


        }


        function bindVerificationData() {
            $.ajax({
                url: '/WebServices/ApplicationSACC.ashx?method=GetVerificationStatusData',
                data: { app_id: getQuerystring('app_id', '') },
                success: function (data) {
                    if (data == "0") {
                        $('#hdnVerifyStatusID').val(0);
                    }
                    else {
                        $.each(eval(data.replace(/[\r\n]/, '')), function (i, rec) {
                            $('#hdnVerifyStatusID').val(rec.verifystatusID);
                            $('#lblbankAttempts').html(rec.bankretrieve_attempts);
                            (rec.idcheck_status == '1') ? document.getElementById("chkID").checked = true : document.getElementById("chkID").checked = false;
                            (rec.bankretrieve_status == '1') ? document.getElementById("chkBank").checked = true : document.getElementById("chkBank").checked = false;
                            (rec.payslip_status == '1') ? document.getElementById("chkPayslip").checked = true : document.getElementById("chkPayslip").checked = false;

                            (rec.creditehistory == '1') ? document.getElementById("chkCreditHistory").checked = true : document.getElementById("chkCreditHistory").checked = false;
                            (rec.incomeexpense == '1') ? document.getElementById("chkIE").checked = true : document.getElementById("chkIE").checked = false;
                            (rec.phoneverification == '1') ? document.getElementById("chkPhone").checked = true : document.getElementById("chkPhone").checked = false;
                            (rec.contractprepared == '1') ? document.getElementById("chkContract").checked = true : document.getElementById("chkContract").checked = false;
                            (rec.contractsigned == '1') ? document.getElementById("chkesign").checked = true : document.getElementById("chkesign").checked = false;
                            (rec.fundtransferred == '1') ? document.getElementById("chkFund").checked = true : document.getElementById("chkFund").checked = false;

                            if (rec.IDCheckFiles > 0)
                                $('#btnIDCheck').linkbutton('enable');
                            if (rec.BankFiles > 0)
                                $('#btnBank').linkbutton('enable');
                            if (rec.PayslipFiles > 0)
                                $('#btnPayslip').linkbutton('enable');

                            $('#lblIDCount').html(rec.IDfiledownloaded);
                            $('#lblPayslipCount').html(rec.payslipdownloaded);
                            $('#lblBankFileCount').html(rec.bankfiledownloaded);
                        });
                    }
                }
            });
        }



        function saveSACCVerificationData() {
            //  $('#chkFund').is(":checked")
            window.onbeforeunload = null;
            var hOperator = $('#ContentPlaceHolder1_appProfile_hdnUserName').val();

            $.ajax({
                url: '/WebServices/ApplicationSACC.ashx?method=saveVerificationStatusData',
                data: {

                    app_id: getQuerystring('app_id', ''),
                    idcheck_status: $('#chkID').is(":checked"),
                    bankretrieve_attempts: $('#lblbankAttempts').text(),
                    bankretrieve_status: $('#chkBank').is(":checked"),
                    payslip_status: $('#chkPayslip').is(":checked"),

                    creditehistory: $('#chkCreditHistory').is(":checked"),
                    incomeexpense: $('#chkIE').is(":checked"),
                    phoneverification: $('#chkPhone').is(":checked"),
                    contractprepared: $('#chkContract').is(":checked"),
                    contractsigned: $('#chkesign').is(":checked"),
                    fundtransferred: $('#chkFund').is(":checked"),
                    historyOperator: hOperator
                },
                success: function (data) {
                }

            });
        }
    </script>
</body>


</html>
